<template>
  <div class="app-container">
    <el-form label-width="120px">
      <el-form-item label="银行名称">
        <el-input
          v-model="bankData.bankName"
          placeholder="请输入"/>
      </el-form-item>

      <el-form-item label="单笔限额">
        <el-input
          v-model="bankData.quotaTime"
          placeholder="请输入"
        />
      </el-form-item>

      <el-form-item label="单日限额">
        <el-input
          v-model="bankData.quotaDay"
          placeholder="请输入"
        />
      </el-form-item>


      <!-- 预售头像：TODO -->
      <el-form-item label="银行图标图片">
        <!-- 头衔缩略图 -->
        <pan-thumb :image="bankData.icon" />
        <!-- 文件上传按钮 -->
        <el-button
          type="primary"
          icon="el-icon-upload"
          @click="imagecropperShow = true"
          >上传图片
        </el-button>
        <!--v-show：是否显示上传组件
            :key：类似于id，如果一个页面多个图片上传控件，可以做区分
            :url：后台上传的url地址
          @close：关闭上传组件
          @crop-upload-success：上传成功后的回调 -->
        <image-cropper
          v-show="imagecropperShow"
          :width="70"
          :height="70"
          :key="imagecropperKey"
          :url="'http://127.0.0.1:8080/minio/upload/bank'"
          field="file"
          @close="close1"
          @crop-upload-success="cropSuccess1" />
      </el-form-item>

  

      <el-form-item>
        <el-button
          :disabled="saveBtnDisabled"
          type="primary"
          @click="saveOrUpdate"
          >保存</el-button>
        <el-button type="info" plain @click="cancleSaveOrUpdate"
          >取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import goldBank from "@/api/goldServer";
import ImageCropper from "@/components/ImageCropper";
import PanThumb from "@/components/PanThumb";

export default {
  components: { PanThumb, ImageCropper },
  data() {
    return {
    
      saveBtnDisabled: false, // 保存按钮是否禁用,
      imagecropperShow: false, //头像上传组件是否显示
      imagecropperKey: 0,
      BASE_API: process.env.BASE_API, //获取dev.env.js里面的地址
      isUse: true,
      bankData:{
        id:"",
        icon:"",
        bankName:"",
        quotaTime:"",
        quotaDay:""
      }
    };
  },
  created() {
    //页面渲染之前执行
    // this.init();
  },
  watch: {
    //监听
    $route(to, from) {
      //路由变化方式，路由发生变化，方法就会执行
      this.init();
    }
  },
  methods: {
    close1() {
      //关闭上传头像组件
      this.imagecropperShow = false;
      //上传失败后，重新打开上传组件时初始化组件，否则显示上一次的上传结果
      this.imagecropperKey = this.imagecropperKey + 1;
    },
    cropSuccess1(data) {
      //上传成功后返回的图片地址
      // this.regular.picUrl = data.fileUrl;
      // console.log(data)
      this.bankData.icon=data;
      //上传头像成功
      this.imagecropperShow = false;
      //上传成功后，重新打开上传组件时初始化组件，否则显示上一次的上传结果
      this.imagecropperKey = this.imagecropperKey + 1;
    },
    
   
    saveOrUpdate() {
      goldBank.saveGoldBank(this.bankData).then((res)=>{
          console.log(res.data)
          if(res.data.code==200){
            //提示信息
            this.$message({
              type: "success",
              message: "修改成功!",
            });
            this.$router.push({ path: "/list/gold" });
          }else{
            //提示信息
            this.$message({
              type: "false",
              message: "修改出了点问题!",
            });
            this.$router.push({ path: "/list/gold" });
          }
      })
    },
   
    //this.$router.push({ path: "/list/regular" });

    //取消操作
    cancleSaveOrUpdate() {
      this.$router.push({ path: "/list/gold" });
    },
  },
};
</script>
